<?php

    ##
    # Makes forms from xml
    class MakeForms {

        public $vezir;
        public $xml;

        function MakeForms($xml,$Vezir=false){
            $this->xml = $xml;
            if (false !== $Vezir)
                $this->vezir=$Vezir;
        }

        function Build($xml,$show,$method="GET") {
            foreach ($xml->table as $tables){
                $show=="all"?$que="all":$que=$tables['name'];
                if ($show==$que){
                $ret.= "<h3>".$xml->name." » ".$tables['title']."</h3>\n";
                $ret.= "<form action='?' method='$method' id='".$tables['name']."' class='cssform'>\n";
                foreach ($tables->field as $fields){
                    $fields['title']<>""?$title=$fields['title']:$title=$fields['name'];
                    $ret.="<p><label for='{$fields['name']}'>{$title}</label>\n";
                    switch ($fields["type"]) {
                        case "text":
                            $ret.="<textarea id='{$fields['name']}' rows='5' cols='35'>{$fields}</textarea>\n";
                        break;
                        case "char":
                            $prop_=split(':',$fields['prop']);
                            switch($prop_[0]){
                                case 'password':
                                    $itype='password';
                                break;
                                default:
                                    $itype='text';
                            }
                            $ret.="<input type='{$itype}' id='{$fields['name']}' value='{$fields}' maxlength='{$fields['size']}' />\n";
                        break;
                        case "set":
                            $values=split(',',$fields['values']);
                            foreach ($values as $val) {
                                $temp=split(':',$val);
                                $value=$temp[0];$temp[1]==""?$caption=$value:$caption=$temp[1];
                                $fields==$value ? $cc="CHECKED":$cc="";
                                $ret.="{$caption} <input type='radio' name='{$fields['name']}' value='{$value}' $cc />";
                            }
                            $ret.="<br />\n";
                        break;
                    }
                    $ret.="</p>\n";
                }
                $ret.="<p><label>Submit</label>
                        <input type='submit' value='Submit' />\n
                        <input type='reset' value='Reset' />\n
                       </p></form>";
                }
            }
            return $ret;
        }

        function ParseForms($show="all"){
            echo $this->Build($this->xml,$show);
        }
    }

?>
